<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2019/4/8
 * Time: 13:52
 */

namespace common\logics\taskorderrecord;

use common\widgets\Tool;
use Yii;
use yii\base\BaseObject;

class TaskOrderRecordLogic extends BaseObject implements ITaskOrderRecord
{
    /** @var \common\sources\read\taskorder\TaskOrderAccess  $RTaskOrderAccess ***/
    private $RTaskOrderAccess;

    public function init()
    {
        $this->RTaskOrderAccess = Yii::$container->get("RTaskOrderAccess");
        parent::init(); // TODO: Change the autogenerated stub
    }

    public function getTaskOrderList($data)
    {
        if(empty($data['buy_id']))
        {
            return Tool::returnJson([],401,"买手id不能为空");
        }
        if(empty($data['safetyCode']))
        {
            return Tool::returnJson([],401,"安全码不能为空");
        }
        if(md5($data['buy_id']) != $data['safetyCode'])
        {
            return Tool::returnJson([],401,"安全码不正确");
        }
        $count = $this->RTaskOrderAccess->getSuccessTaskOrderCount($data);
        $list = [];
        if($count >0)
        {
            $list = $this->RTaskOrderAccess->getSuccessTaskOrderList($data);
            foreach ($list as &$item)
            {
                $item['plat_type_name'] = isset($item['plat_type']) ? Yii::$app->params['plat_type'][$item['plat_type']] : '';
                $item['refund_amount'] = ($item['return_type'] == 1) ?  $item['refund_amount'] :($item['return_type'] == 2 ?  0.00 :"");
                $item['remark'] = "任务完成返还资金";
            }
        }
        return Tool::returnJson([
            "list" => $list,
            "count" => $count,
            "page_num" => $data['page_num']
        ],200,"成功");


    }
}